home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** File: Window.c
- ** Written by: Eric Soldan
- **
- ** Copyright © 1990-1993 Apple Computer, Inc.
- ** All rights reserved.
- */
-
- /* You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes. */
-
- /* This file contains the code for the document procedure pointers for the main Wannabe
- ** document. Wannabe currently only supports one type of documents, type 'DUMD',
- ** which stands for "DUMb Document". */
-
- /* For more information on this file, please read the read.me file "=How to write your app". */
-
-
-
- /*****************************************************************************/
-
-
-
- #include "App.h" /* Get the application includes/typedefs, etc. */
- #include "App.defs.h" /* Get various application definitions. */
- #include "App.protos.h" /* Get the prototypes for application. */
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef __FINDER__
- #include <Finder.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif
-
- #ifdef powerc
- #pragma options align=mac68k
- #endif
- typedef struct xFSSpec {
- FSSpec **fss;
- Str32 oldName;
- } xFSSpec;
- #ifdef powerc
- #pragma options align=reset
- #endif
-
-
-
- /*****************************************************************************/
-
-
-
- extern TreeObjHndl gWindowFormats;
-
- static void CreatePart(WindowPtr window);
- static void FixupAliases(WindowPtr window);
- static OSErr FullPathFromAlias(AliasHandle alias, StringPtr aliasPath, StringPtr aliasName);
- static OSErr FullPathFromFSSpec(const FSSpec *spec, StringPtr fsPath, StringPtr fsName);
-
- static void MyFindText(long *offset);
- static void MyReplaceText(long *offset);
- static void FixNMAPs(StringPtr pstr, StringPtr qstr);
- static void MergeCustomResources(short out, short in);
-
- static void IndCNum2Ctl(WindowPtr window, short cnum, short cset, ControlHandle *ctl);
- static void VisCNum2Ctl(WindowPtr window, short cnum, ControlHandle *ctl);
-
- static char *gText;
- static char *gFText;
- static char *gRText;
- static long gLen, gFLen, gRLen;
- static Boolean gOpenedDoc, gNoReplace;
- static short gDataSetBase = 5000;
-
- static xFSSpec gFSSpec[512];
- static AliasHandle gAlias[128];
- static short gResolveIndx;
-
- static OSErr CacheFile(FSSpec out, FSSpec in, short *oldDepth, short newDepth);
- static short gRsrcNum;
-
- Boolean gNoDefaultDocument = false;
- /* Set to true if app should boot with no default document. */
- /* This tells DTS.Lib..framework what you want. */
-
- OSType gAppWindowType = kDocFileType; /* Main document type. */
- long gAppWindowAttr = kwAppWindow; /* Main window attributes. */
-
- short gMinVersion = kMinVersion; /* Minimum document version app can support. */
- short gMaxVersion = kMaxVersion; /* Maximum document version app can support. */
- /* More informing DTS.Lib..framework. */
-
- extern short gPrintPage; /* Non-zero means we are printing. */
- /* DTS.Lib..framework global. */
-
- extern RgnHandle gCursorRgn; /* We handle cursors here, so we need */
- extern CursPtr gCursorPtr; /* to know about these things. */
- /* Above are DTS.Lib..framework globals. */
-
- /* Currently Wannabe doesn't ever change the cursor, so we don't actually need
- ** these referenced here. However, since Wannabe is supposed to be an application
- ** in progress, it is very likely that you will need to reference these as your
- ** project develops. See DTS.StyleChat and DTS.Draw for examples of setting the cursor. */
-
- /* Some cursors are pointer-based, and some cursors are resource-based.
- ** If a cursor is resource-based, it needs to be loaded and made to not move,
- ** and then gCursorPtr can be set to point to it. This makes all cursors
- ** pointer-based. Also, gCursorPtr is used by DTS.Lib..framework to
- ** determine if there is a current cursor. If gCursorPtr is nil, then
- ** there is no current cursor, and the cursor has to be recalculated, no
- ** matter where the mouse is. If gCursorPtr is not nil, then if the
- ** mouse position is within the cursor region gCursorRgn, the cursor is
- ** correct, and no recalculation is necessary. If it is outside this region,
- ** then it is recalculated. What does this all mean? It means that if you
- ** want to guarantee that the cursor is recalculated next time DoWindowCursor()
- ** is called, set gCursorPtr to nil.
- **
- ** If you have a cursor resource, you need to:
- ** 1) Load the resource.
- ** 2) Make a fixed copy of it.
- ** 3) Set the cursor to it.
- ** 4) Set gCursorPtr to point to the fixed copy.
- **
- ** There is a function that does almost all of this, called DoSetResCursor().
- ** It does all but set gCursorPtr to it. (It actually sets gCursorPtr to nil.)
- ** It does return a pointer to the permanent copy, so typically what you will
- ** want to do is the following:
- ** gCursorPtr = DoSetResCursor(theCursorID);
- **
- ** So why set gCursorPtr to nil as the default action? This allows you to
- ** set a temporary cursor, which will be replaced when DoWindowCursor() is
- ** called next, or it allows you to set a cursor that maps to the cursor
- ** region gCursorRgn (by setting gCursorPtr to the return result). */
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
-
- #ifdef applec
- #pragma segment Window
- #endif
-
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* Calculate application specific frame area (Called by DoCalcFrameRgn).
- ** You are passed an empty region. You are supposed to add any custom frame
- ** parts that this document uses. Typically there are no frame portions, as
- ** they are accounted for in other ways. The scrollbars and grow icon will
- ** automatically be contributed to the calculation of the frame region.
- ** If you use sidebars, these are also added in automatically. This is only
- ** used if the frame region is more complicated than can automatically be
- ** handled. So, almost always, you will simply leave the region empty. */
-
- void CalcFrameRgn(FileRecHndl frHndl, WindowPtr window, RgnHandle rgn)
- {
- #ifndef __MWERKS__
- #pragma unused (frHndl, window, rgn)
- #endif
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* This is called (by DoContentClick()) when a mouse-down event occurs in the content of
- ** a window. Other applications might want to call FindControl, TEClick, etc., to
- ** further process the click. */
-
- void ContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
- {
- #ifndef __MWERKS__
- #pragma unused (firstClick)
- #endif
-
- ControlHandle ctl;
- short action, cnum, oldRes, modifiers, optkey, numAdded;
- FileRecHndl frHndl, aboutDoc;
- OSErr err;
-
- frHndl = (FileRecHndl)GetWRefCon(window);
- PrepDocResFile(frHndl, &oldRes, fsRdPerm);
-
- cnum = IsCtlEvent(window, event, &ctl, &action);
- /* That was easy. Scrolling was just handled. Other stuff would be handled
- ** by IsCtlEvent, if we had other stuff to do. We don't have any other
- ** controls in the content besides the document scrollbars. */
-
- if (cnum == kWhichDataSet) {
- VisCNum2Ctl(window, kNewClassName, &ctl);
- if (ctl) {
- CTESetSelect(0, 32767, (TEHandle)GetControlReference(ctl));
- CTEActivate(true, (TEHandle)GetControlReference(ctl));
- }
- }
-
- if (cnum == kAboutDocument) {
- err = GetSeparateWFMT('ABTD', &numAdded);
- if (!err) {
- err = NewDocument(&aboutDoc, 'ABTD', false);
- if (!err) {
- err = DoNewWindow(aboutDoc, nil, window, (WindowPtr)-1);
- if (err) DisposeDocument(aboutDoc);
- }
- }
- GetSeparateWFMT(0, &numAdded);
- }
-
- if (cnum == -1) {
- modifiers = event->modifiers;
- optkey = (modifiers & optionKey);
- if (optkey) gNoReplace = true;
- CreatePart(window);
- FixupAliases(window);
- }
- gNoReplace = false;
-
- // CloseDocResFile(frHndl);
- UseResFile(gAppResRef);
-
- return;
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* DoKeyDown() is first called by the application. Then if the key isn't a menu
- ** key, DoKeyDown() calls this code. Here are the rules for this function:
- **
- ** 1) If you handle the key, return(true). This completes the key handling.
- ** 2) If you don't handle the key, you return false. However, there are two
- ** situations for not handling the key:
- ** a) You want someone else to.
- ** b) You want nobody else to look at the key.
- ** This is what the boolean passThrough is for. If you wish the next window
- ** to have a look at the key, set the boolean passThrough to true. passThrough
- ** is already initialized to false, which is the common case, so you only have
- ** to worry about setting it true.
- **
- ** If you have a window that never processes keys and always passes them through,
- ** just set the contentKeyProc to nil. This will indicate to the application
- ** framework that all keys should be passed through this window. DTS.Draw has
- ** such a window. Its palette window doesn't accept keys. They are passed through
- ** to document windows. */
-
- Boolean ContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough)
- {
- #ifndef __MWERKS__
- #pragma unused (passThrough)
- #endif
-
- short cnum, oldRes, numAdded;
- OSErr err;
- FileRecHndl frHndl, aboutDoc;
-
- frHndl = (FileRecHndl)GetWRefCon(window);
- PrepDocResFile(frHndl, &oldRes, fsRdPerm);
-
- cnum = IsCtlEvent(window, event, nil, nil);
- /* See DTS.Draw for an example of what you might do here. */
-
- if (cnum == -1) {
- CreatePart(window);
- FixupAliases(window);
- }
-
- if (cnum == kAboutDocument) {
- err = GetSeparateWFMT('ABTD', &numAdded);
- if (!err) {
- err = NewDocument(&aboutDoc, 'ABTD', false);
- if (!err) {
- err = DoNewWindow(aboutDoc, nil, window, (WindowPtr)-1);
- if (err) DisposeDocument(aboutDoc);
- }
- }
- GetSeparateWFMT(0, &numAdded);
- }
-
- // CloseDocResFile(frHndl);
- UseResFile(gAppResRef);
-
- return(true);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* Draw application specific content (Called by DoDrawFrame).
- **
- ** If your application has any custom frame areas, or if it uses sidebars,
- ** this is the function that you would put the frame drawing code. The
- ** document scrollbars and grow icon drawing is handled by DTS.framework.
- ** Just do the sidebar and custom areas here. */
-
- void DrawFrame(FileRecHndl frHndl, WindowPtr window, Boolean activate)
- {
- MoveTo(0, (*frHndl)->fileState.topSidebar - 1);
- LineTo((*frHndl)->fileState.leftSidebar - 1 - 16384, (*frHndl)->fileState.topSidebar - 1);
- LineTo((*frHndl)->fileState.leftSidebar - 1 - 16384, 16383);
-
- BeginFrame(window);
- DoDrawControls(window, activate);
- EndFrame(window);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* Frees up any application-specific memory in the document. This is called by
- ** DoFreeDocument, which is called by DisposeDocument(). The application would
- ** call DisposeDocument(), not DoFreeDocument() or FreeDocument() directly.
- **
- ** The document may have a bunch of handles off the main handle of the document.
- ** This is where they are freed. DisposeDocument calls this prior to releasing
- ** the ram for the main handle of the document, so release everything else
- ** here, or you will have a memory leak.
- **
- ** NOTE: Calling DefaultFreeDocument() frees up all memory used by a
- ** hierarchical document (see TreeObj package). */
-
- OSErr FreeDocument(FileRecHndl frHndl)
- {
- return(DefaultFreeDocument(frHndl));
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* Any additional window disposal tasks can be handled here. */
-
- OSErr FreeWindow(FileRecHndl frHndl, WindowPtr window)
- {
- #ifndef __MWERKS__
- #pragma unused (window)
- #endif
-
- WindowPtr ww;
- FileRecHndl ff;
-
- if ((*frHndl)->fileState.sfType == 'PtMd') {
- for (ww = nil; (ww = GetNextDocumentWindow(ww, 0)) != nil;) {
- ff = (FileRecHndl)GetWRefCon(ww);
- if ((*ff)->fileState.sfType == kViewHierFileType) {
- if ((*frHndl)->d.doc.root == (*ff)->d.doc.root) {
- DisposeOneWindow(ww, kClose);
- ww = nil;
- }
- }
- }
- }
-
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* Image the document into the current port.
- **
- ** The only thing tricky about this function is that it needs to key off of
- ** the global variable gPrintPage. gPrintPage is the current page that is
- ** being printed. If gPrintPage is 0, then you are drawing to the window.
- **
- ** For when printing:
- **
- ** If gPrintPage is non-0, that is the page to be printed. If after imaging
- ** the page there are no more pages, you should set gPrintPage to 0. This
- ** indicates to the print loop that the end of the document has been reached.
- ** Even if the user indicated in the job dialog to print more pages, setting
- ** gPrintPage to 0 states that the last page has been printed. This is necessary
- ** because the print loop can't know when printing is done. The imaging procedure
- ** is the logical one to state when everything has been imaged. */
-
- OSErr ImageDocument(FileRecHndl frHndl)
- {
- #ifndef __MWERKS__
- #pragma unused (frHndl)
- #endif
-
- short oldRes;
-
- PrepDocResFile(frHndl, &oldRes, fsRdPerm);
-
- DoDrawControls((*frHndl)->fileState.window, false); /* Draw the content controls. */
- gPrintPage = 0;
-
- UseResFile(oldRes);
-
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* This function does the remaining window initialization.
- **
- ** There may be additional content initialization for the window. At this point,
- ** you have a window, but it is currently invisible. If you return noErr, then
- ** the window will be set to the state indicated for that window. Why this function?
- ** You may wish to add controls to the content of the window. You may have a
- ** TextEdit record in the content. All of these sort of things can't be created
- ** until there is a window to contain them. First a document is read in, and then
- ** if the document creation succeeds, a window is created for that document.
- ** At this point we have a document, and we are on our way to having a window.
- ** All that remains is any additional content initialization. Do it, return
- ** noErr, and everybody's happy. If something goes wrong here, return the error,
- ** and the incomplete window will be disposed of. */
-
- Boolean ProperClassName(TEHandle teHndl, EventRecord *event, short *handled);
- OSErr InitContent(FileRecHndl frHndl, WindowPtr window)
- {
- OSErr err;
- ControlHandle ctl, cc, aw;
- TEHandle te;
- short oldRes, numAdded, cset;
- Str255 pstr;
- StringHandle sh;
-
- err = noErr;
-
- if ((*frHndl)->fileState.sfType == 'PtMd') {
-
- err = PrepDocResFile(frHndl, &oldRes, fsRdPerm);
- if (err) return(err);
-
- GetSeparateWFMT('PtMd', &numAdded);
- err = AddControlSet(window, (*frHndl)->fileState.sfType, kwStandardVis, 0, 0, nil);
- GetSeparateWFMT(0, &numAdded);
-
- if (err) {
- CloseDocResFile(frHndl);
- UseResFile(gAppResRef);
- return(err);
- }
-
- for (cset = 1;; ++cset) {
- IndCNum2Ctl(window, kNewClassName, cset, &ctl);
- /* IndCNum2Ctl gets the controlof id/refcon, which
- ** in this case is kNewClassName/cset. */
- if ((!ctl) && (cset)) break;
- if (!ctl) continue;
- te = (TEHandle)GetControlReference(ctl);
- IndCNum2Ctl(window, kAppWannabeCreator, cset, &aw);
- if (!aw) CTESetKeyFilter(te, ProperClassName);
-
- IndCNum2Ctl(window, kOldClassName, cset, &cc);
- if (cc) {
- pcpy(pstr, (*cc)->contrlTitle);
- CTEPutPStr(ctl, pstr);
- CTESetSelect(0, 32767, (TEHandle)GetControlReference(ctl));
- }
- else {
- sh = GetString(5000);
- pcpy(pstr, *sh);
- pstr[1] = pstr[0] - 1;
- CTEPutPStr(ctl, pstr + 1);
- CTESetSelect(0, 32767, (TEHandle)GetControlReference(ctl));
- }
- }
-
- for (cset = 1;; ++cset) {
- IndCNum2Ctl(window, kNewCompanyName, cset, &ctl);
- if ((!ctl) && (cset)) break;
- if (!ctl) continue;
-
- te = (TEHandle)GetControlReference(ctl);
- CTESetKeyFilter(te, ProperClassName);
- IndCNum2Ctl(window, kOldCompanyName, cset, &cc);
- if (cc) {
- pcpy(pstr, (*cc)->contrlTitle);
- CTEPutPStr(ctl, pstr);
- CTESetSelect(0, 32767, (TEHandle)GetControlReference(ctl));
- }
- }
-
- // CloseDocResFile(frHndl);
- UseResFile(gAppResRef);
-
- gOpenedDoc = true;
- return(noErr);
- }
-
- return(err);
- }
-
- Boolean ProperClassName(TEHandle te, EventRecord *event, short *handled)
- {
- char key;
- short i;
- Boolean validChar;
-
- key = event->message & charCodeMask;
- i = event->modifiers & keyCodeMask;
- if (i & cmdKey) return(false);
- if (i & optionKey) return(false);
- if (key == 8) return(false);
- if (key == 9) return(false);
- if ((key >= 28) && (key <= 31)) return(false);
-
- validChar = false;
- if ((key >= 'A') && (key <= 'Z')) validChar = true;
- if ((key >= 'a') && (key <= 'z')) validChar = true;
- if ((*te)->selStart) {
- if ((key >= '0') && (key <= '9')) validChar = true;
- if (key == '_') validChar = true;
- }
- if (validChar) return(false);
-
- return(true);
- }
-
- void DoFolders(void)
- {
- WindowPtr window, rww;
- FileRecHndl frHndl, rff;
- OSErr err;
- Boolean isDirectory;
- FSSpec fss, fssd, matches[1];
- long mcount;
- short iloc, p1, p2, pp, res, oldRes, oldRes2, i;
- long pid[128];
- TreeObjHndl cobj;
-
- oldRes = CurResFile();
-
- DoSetResCursor(watchCursor);
-
- for (i = (*gWindowFormats)->numChildren; i; ) {
- cobj = GetChildHndl(gWindowFormats, --i);
- if (mDerefWFMT(cobj)->sfType == 'fold') break;
- }
- if (!i) return;
-
- for (;;) {
-
- window = GetNextDocumentWindow(nil, 'fold');
- if (!window) break;
- frHndl = (FileRecHndl)GetWRefCon(window);
-
- fss = (*frHndl)->fileState.fss;
- fssd = fss;
- err = DirIDFromFSSpec(&fss, &fssd.parID, &isDirectory);
-
- if (fss.name[0] == 31) fss.name[0]--;
- pcat(fss.name, "\p•");
-
- p1 = pp = 0;
- pid[pp++] = matches[0].parID;
- iloc = 0;
- gRsrcNum = 5000;
- do {
- err = FindEverything(fssd.vRefNum, fssd.parID, matches, 1, &mcount, false);
- if (mcount) {
- for (p2 = 0; p2 < pp; ++p2) if (pid[p2] == matches[0].parID) break;
- pid[p2++] = matches[0].parID;
- pp = p2;
- CacheFile(fss, matches[0], &p1, p2);
- }
- } while (err == noErr);
-
- res = HOpenResFile(fss.vRefNum, fss.parID, fss.name, fsRdWrPerm);
- err = ResError();
- if (!err) {
- for (rww = nil; (rww = GetNextDocumentWindow(rww, 'rsrc')) != nil;) {
- rff = (FileRecHndl)GetWRefCon(rww);
- if (!UseDocResFile(rff, &oldRes2, fsRdPerm)) {
- MergeCustomResources(res, CurResFile());
- CloseDocResFile(rff);
- UseResFile(oldRes2);
- }
- }
- for (rww = nil; (rww = GetNextDocumentWindow(rww, 'RSRC')) != nil;) {
- rff = (FileRecHndl)GetWRefCon(rww);
- if (!UseDocResFile(rff, &oldRes2, fsRdPerm)) {
- MergeCustomResources(res, CurResFile());
- CloseDocResFile(rff);
- UseResFile(oldRes2);
- }
- }
- }
-
- DisposeOneWindow(window, kClose);
- }
-
- UseResFile(oldRes);
- }
-
- void MergeCustomResources(short out, short in)
- {
- short tt, ii, nt, ni, rid;
- ResType rtype;
- Str255 rname;
- char rattr;
- Handle rr, oldr;
-
- UseResFile(in);
- nt = Count1Types();
-
- for (tt = nt; tt; --tt) {
-
- Get1IndType(&rtype, tt);
- ni = Count1Resources(rtype);
-
- for (ii = ni; ii; --ii) {
-
- rr = Get1IndResource(rtype, ii);
- if (!rr) continue;
-
- GetResInfo(rr, &rid, &rtype, rname);
- rattr = GetResAttrs(rr);
-
- DetachResource(rr);
- UseResFile(out);
-
- oldr = Get1Resource(rtype, rid);
- if (oldr) {
- RemoveResource(oldr);
- DisposeHandle(oldr);
- }
-
- AddResource(rr, rtype, rid, rname);
- SetResAttrs(rr, rattr);
- ChangedResource(rr);
- WriteResource(rr);
- DetachResource(rr);
- DisposeHandle(rr);
-
- UseResFile(in);
- }
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* The code below assumes that you are using the hierarchical document package.
- ** If you are, the entire hierarchical document is read in with just these two
- ** calls. If you don't use it, you are on your own. See DTS.StyleChat for an
- ** example of an application that uses the DTS.framework without the hierarchical
- ** document package. */
-
- OSErr ReadDocument(FileRecHndl frHndl)
- {
- return(noErr);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* Resize application specific content (Called by ResizeWindow).
- **
- ** This gets called when a user does a zoom or window resizing operation.
- ** It is possible that things in the content need to be resized in conjunction
- ** with the resizing of the window. */
-
- void ResizeContent(WindowPtr window, short oldh, short oldv)
- {
- #ifndef __MWERKS__
- #pragma unused (window, oldh, oldv)
- #endif
-
- /* See DTS.StyleChat for a sample usage of this function. */
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* Scroll application specific frame (Called by DoScrollFrame).
- **
- ** Some applications may need to scroll the "frame" of the document along
- ** with the document contents. This is common for applications with rulers,
- ** or other similar sidebar items. */
-
- void ScrollFrame(FileRecHndl frHndl, WindowPtr window, long dh, long dv)
- {
- #ifndef __MWERKS__
- #pragma unused (frHndl, window, dh, dv)
- #endif
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* Since the hierarchical document package isn't used by DTS.StyleChat,
- ** this function actually never gets called. */
-
- void UndoFixup(FileRecHndl frHndl, Point contOrg, Boolean afterUndo)
- {
- #ifndef __MWERKS__
- #pragma unused (frHndl, contOrg, afterUndo)
- #endif
-
- /* See DTS.Draw for an example of what you might do here. */
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* This function is where you adjust the cursor to reflect the location in the
- ** document or window. You have the additional input of gCursorRgn to deal
- ** with. The way that the cursor handling works is as follows:
- ** 1) The application calls DoWindowCursor().
- ** 2) DoWindowCursor() works its way through the windows/documents, front to back.
- ** It looks at the document's windowCursorProc and checks to see if the document
- ** has one. If the document doesn't have one, then it assumes that that window
- ** always wants an arrow. If the cursor is over that window, the cursor is set
- ** to an arrow, and we're done. If the cursor isn't over the window, then the next
- ** window is tried. If all documents don't have a windowCursorProc, then the cursor
- ** is set to an arrow (for the non-document area of the screen).
- ** 3) If a document has a windowCursorProc, then the proc is called. The proc's
- ** job is as follows:
- ** a) If the cursor is over a position that is determined by the window, then
- ** the proc removes other areas from gCursorRgn. Note that it should not
- ** simply set the area to what it "thinks" is the correct area. This window
- ** may not be the front-most. Other windows will have already been subtracted
- ** from gCursorRgn. The resultant gCursorRgn is the correct cursor area,
- ** and should be passed to WaitNextEvent calls in the application (already the case
- ** in EventLoop.c). Also, the cursor should be set to the correct cursor, of course.
- ** You should also return true, as the cursor has been determined.
- ** b) If the cursor is not over a position for this window, then you should
- ** return. You will either pass back true or false. If you don't wish
- ** windows behind this window to have a shot at cursor determination, then
- ** return true. This states that the cursor is "determined". It is, in the
- ** sense that no further determination will occur. If you return false, then
- ** other windows get a shot at determining the cursor.
- **
- ** Setting the cursor to the correct cursor isn't as easy as you would expect.
- ** DTS.Lib..framework uses the global gCursorPtr as the reference to the cursor. This is
- ** fine if the cursor is pointer-based, but if the cursor is resource-based, it is a bit
- ** more of a problem. What you will need to do is to call DoSetResCursor() to make the
- ** resource cursor pointer-based. DoSetResCursor() will set gCursorPtr to nil, and it
- ** also returns the pointer to the permanent copy of the cursor resource. Just set gCursorPtr
- ** to the return result of DoSetResCursor(), and you will be set. */
-
- Boolean WindowCursor(FileRecHndl frHndl, WindowPtr window, Point globalPt)
- {
- WindowPtr oldPort;
- RgnHandle contRgn;
- Rect rr, teViewRct, contRct;
- TEHandle teHndl;
- ControlHandle viewCtl;
- Point contOrg;
- CTEDataHndl teData;
- short mode;
-
- if (!window) {
- SetCursor(gCursorPtr = &qd.arrow);
- return(true);
- }
-
- oldPort = SetFilePort(frHndl);
- window = (*frHndl)->fileState.window;
-
- GetContentOrigin(window, &contOrg);
- SetOrigin(contOrg.h, contOrg.v); /* Scroll position of window. */
-
- GetContentRect(window, &contRct);
- /* This returns the content portion of the window in local coordinates,
- ** less document scrollbar and sidebar areas. */
-
- contRgn = NewRgn();
- for (viewCtl = nil; ((viewCtl = CTENext(window, &teHndl, viewCtl, 1, false)) != nil);) {
- teViewRct = (*teHndl)->viewRect;
- SectRect(&teViewRct, &contRct, &rr);
- LocalToGlobalRect(&rr);
- if ((*viewCtl)->contrlVis) {
- if (!(*viewCtl)->contrlHilite) {
- if (!CTEReadOnly(teHndl)) {
- RectRgn(contRgn, &rr);
- teData = (CTEDataHndl)(*viewCtl)->contrlData;
- mode = (*teData)->mode;
- if ((mode & cteActive) || (!(mode & cteTwoStep))) {
- if (PtInRect(globalPt, &rr)) {
- gCursorPtr = DoSetResCursor(iBeamCursor);
- SectRgn(gCursorRgn, contRgn, gCursorRgn);
- DisposeRgn(contRgn);
- SetPort(oldPort);
- return(true);
- }
- }
- DiffRgn(gCursorRgn, contRgn, gCursorRgn);
- }
- }
- }
- }
- SetCursor(gCursorPtr = &qd.arrow);
- DisposeRgn(contRgn);
- return(true);
- }
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* After the DTS.Lib framework disposes of a window, it calls here. This is
- ** to give the application a chance to do any additional tasks related to
- ** a window closing. DTS.StyleChat doesn't have anything else extra to do. */
-
- void WindowGoneFixup(WindowPtr window)
- {
- #ifndef __MWERKS__
- #pragma unused (window)
- #endif
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- /* The reverse function of ReadDocument. */
-
- OSErr WriteDocument(FileRecHndl frHndl)
- {
- return(DefaultWriteDocument(frHndl));
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- Boolean AdjustMenuItems(WindowPtr window, short menuID)
- {
- Boolean redrawMenuBar;
- MenuHandle menu;
-
- redrawMenuBar = false;
-
- switch (menuID) {
- case mFile:
- redrawMenuBar = DoAdjustFileMenu(window);
- break;
- case mEdit:
- redrawMenuBar = DoAdjustEditMenu(window);
- break;
- default:
- menu = GetMenuHandle(menuID);
- if (menu)
- (*menu)->enableFlags |= 0xFFFFFFFEL;
- break;
- }
-
- return(redrawMenuBar);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- /* •• You don't call this. DTS.Lib..framework does for appropriate document type(s). •• */
-
- Boolean DoMenuItem(WindowPtr window, short menuID, short menuItem)
- {
- #ifndef __MWERKS__
- #pragma unused (window)
- #endif
-
- return(DoMenuCommand(menuID, menuItem));
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- static void MyFindText(long *offset)
- {
- long ll;
- char c1, c2;
-
- if (gNoReplace) {
- *offset = gLen;
- return;
- }
-
- for (;*offset < gLen; ++*offset) {
- c1 = gText[*offset]; if ((c1 >= 'a') && (c1 <= 'z')) c1 -= 32;
- c2 = gFText[0]; if ((c2 >= 'a') && (c2 <= 'z')) c2 -= 32;
- if (c1 == c2) {
- if (gLen - *offset < gFLen) {
- *offset = gLen;
- return;
- };
-
- for (ll = 1; ll < gFLen; ++ll) {
- c1 = gText[*offset + ll]; if ((c1 >= 'a') && (c1 <= 'z')) c1 -= 32;
- c2 = gFText[ll]; if ((c2 >= 'a') && (c2 <= 'z')) c2 -= 32;
- if (c1 != c2) break;
- }
- if (ll == gFLen) return;
- }
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- static void MyReplaceText(long *offset)
- {
- long i;
- char c1;
- Boolean upperCase, lowerCase;
-
- upperCase = lowerCase = true;
- for (i = 0; i < gFLen; ++i) {
- c1 = gText[*offset + i];
- if ((c1 >= 'a') && (c1 <= 'z')) upperCase = false;
- if ((c1 >= 'A') && (c1 <= 'Z')) lowerCase = false;
- }
-
- BlockMove(
- gText + *offset + gFLen,
- gText + *offset + gFLen + (gRLen - gFLen),
- gLen - (*offset + gFLen)
- );
-
- BlockMove(gRText, gText + *offset, gRLen);
- if (upperCase) {
- for (i = 0; i < gRLen; ++i) {
- c1 = gText[*offset + i];
- if ((c1 >= 'a') && (c1 <= 'z')) gText[*offset + i] -= 32;
- }
- }
- if (lowerCase) {
- for (i = 0; i < gRLen; ++i) {
- c1 = gText[*offset + i];
- if ((c1 >= 'A') && (c1 <= 'Z')) gText[*offset + i] += 32;
- }
- }
-
- *offset += gRLen;
- gLen += (gRLen - gFLen);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- static Boolean UpdateString(StringPtr s, StringPtr fs, StringPtr rs);
- static Boolean UpdateString(StringPtr s, StringPtr fs, StringPtr rs)
- {
- Str255 scmp;
- short dd, i;
- Boolean update;
-
- if (!fs[0]) return(false);
-
- update = false;
- for (i = s[0] - fs[0] + 1; i > 0; --i) {
- if (s[i] == fs[1]) {
- BlockMove( (s + i), (scmp + 1), (scmp[0] = fs[0]) );
- if (!pcmp(scmp, fs)) {
- update = true;
- dd = (rs[0] - fs[0]);
- BlockMove( (s + i + fs[0]),
- (s + i + fs[0] + dd),
- (s[0] - i + 1)
- );
- BlockMove( (rs + 1),
- (s + i),
- (rs[0])
- );
- s[0] += dd;
- }
- }
- }
-
- return(update);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- static Boolean UpdateHandle(Handle h, StringPtr fs, StringPtr rs, Boolean resize);
- static Boolean UpdateHandle(Handle h, StringPtr fs, StringPtr rs, Boolean resize)
- {
- Str255 scmp;
- long dd, i, hl, fl, rl;
- Boolean update;
-
- if (!fs[0]) return(false);
-
- update = false;
- hl = GetHandleSize(h);
- fl = fs[0] + 1;
- rl = rs[0] + 1;
- for (i = hl - fl; i >= 0; --i) {
- if ((*h)[i + 1] == fs[1]) {
- BlockMove((*h + i), scmp, fl);
- if (!pcmp(scmp, fs)) {
- update = true;
- dd = (rl - fl);
- if (resize)
- if (dd > 0)
- SetHandleSize(h, hl + dd);
- if (resize)
- BlockMove( (*h + i + fl), (*h + i + fl + dd), (hl - i - fl) );
- BlockMove(rs, *h + i, rl);
- if (resize)
- if (dd < 0)
- SetHandleSize(h, hl + dd);
- hl += dd;
- }
- }
- }
-
- return(update);
- }
-
-
-
- /*****************************************************************************/
-
-
-
- static void FixNMAPs(StringPtr str1, StringPtr str2)
- {
- OSType rt, sft;
- short rn, sz, phz, keyListLen, keyListTyp, valueListLen, ii;
- OSType oo;
- Handle hh, hr;
- Ptr hrp, hhp;
- Str255 pstr;
- Boolean update;
-
- if (gNoReplace) return;
-
- update = false;
- for (rt = 'NMAP'; rt <= 'nmap'; rt += ('nmap' - 'NMAP')) {
-
- for (rn = Count1Resources(rt); rn; --rn) {
-
- hr = Get1IndResource(rt, rn);
- HLock(hr);
- hrp = *hr;
-
- hh = NewHandle(4096);
- HLock(hh);
- hhp = *hh;
-
- for (phz = 0; phz != -1;) {
- sz = hrp - *hr;
- if (sz >= GetHandleSize(hr)) break;
- switch (phz) {
- case 0:
- case 2:
- case 20:
- case 21:
- case 32:
- case 33:
- BlockMove(hrp, &sz, sizeof(short));
- hrp += sizeof(short);
- pstr[0] = sz;
- BlockMove(hrp, pstr + 1, pstr[0]);
- hrp += pstr[0];
- if (UpdateString(pstr, str1, str2)) update = true;
- *(short *)hhp = pstr[0];
- hhp += sizeof(short);
- BlockMove(pstr + 1, hhp, pstr[0]);
- hhp += pstr[0];
- switch (phz) {
- case 0:
- phz = 1;
- break;
- case 2:
- phz = 3;
- break;
- case 20:
- phz = 99;
- break;
- case 21:
- phz = 22;
- break;
- case 32:
- phz = 33;
- break;
- case 33:
- phz = 31;
- break;
- }
- break;
- case 1:
- BlockMove(hrp, &keyListLen, sizeof(short));
- hrp += sizeof(short);
- BlockMove(&keyListLen, hhp, sizeof(short));
- hhp += sizeof(short);
- phz = 2;
- break;
- case 3:
- BlockMove(hrp, &keyListTyp, sizeof(short));
- hrp += sizeof(short);
- BlockMove(&keyListTyp, hhp, sizeof(short));
- hhp += sizeof(short);
- phz = keyListTyp + 3; // Cases 4-7 handled separately.
- break;
- case 4:
- BlockMove(hrp, &sft, sizeof(OSType));
- hrp += sizeof(OSType);
- BlockMove(&sft, hhp, sizeof(OSType));
- hhp += sizeof(OSType);
- phz = 99; // Continue processing keyList.
- break;
- case 5:
- BlockMove(hrp, &ii, sizeof(short));
- hrp += sizeof(short);
- BlockMove(&ii, hhp, sizeof(short));
- hhp += sizeof(short);
- BlockMove(hrp, &ii, sizeof(short));
- hrp += sizeof(short);
- BlockMove(&ii, hhp, sizeof(short));
- hhp += sizeof(short);
- phz = 20; // wstring, followed by processing keyList.
- break;
- case 6:
- case 9:
- phz = 20; // wstring, followed by processing keyList.
- break;
- case 7:
- BlockMove(hrp, &valueListLen, sizeof(short));
- hrp += sizeof(short);
- BlockMove(&valueListLen, hhp, sizeof(short));
- hhp += sizeof(short);
- phz = 21;
- break;
- case 8:
- BlockMove(hrp, &valueListLen, sizeof(short));
- hrp += sizeof(short);
- BlockMove(&valueListLen, hhp, sizeof(short));
- hhp += sizeof(short);
- phz = 30;
- break;
- case 22:
- case 31:
- --phz; // was phz = 21;
- if (!(--valueListLen)) phz = 99;
- break;
- case 30:
- BlockMove(hrp, &oo, sizeof(OSType));
- hrp += sizeof(OSType);
- BlockMove(&oo, hhp, sizeof(OSType));
- hhp += sizeof(OSType);
- BlockMove(hrp, &oo, sizeof(OSType));
- hrp += sizeof(OSType);
- BlockMove(&oo, hhp, sizeof(OSType));
- hhp += sizeof(OSType);
-
- // Parse UserString (integer, integer, wstring)
- BlockMove(hrp, &ii, sizeof(short));
- hrp += sizeof(short);
- BlockMove(&ii, hhp, sizeof(short));
- hhp += sizeof(short);
- BlockMove(hrp, &ii, sizeof(short));
- hrp += sizeof(short);
- BlockMove(&ii, hhp, sizeof(short));
- hhp += sizeof(short);
-
- // Parse first wstring in case 32
-
- // Parse Category ISOString (wstring) in case 33
-
- phz = 32;
- break;
- case 99:
- phz = 3;
- if (!(--keyListLen)) phz = -1;
- break;
- }
- }
-
- sz = hhp - *hh;
- HUnlock(hr);
- HUnlock(hh);
- if (update) {
- SetHandleSize(hr, sz);
- BlockMove(*hh, *hr, sz);
- ChangedResource(hr);
- WriteResource(hr);
- }
- DisposeHandle(hh);
- }
- }
- }
-
-
-
- /*****************************************************************************/
-
-
-
- void UpdateFileName(StringPtr fname, StringPtr oldpname, StringPtr newpname,
- StringPtr prefix, StringPtr suffix);
-
- void UpdateFileName(StringPtr fname, StringPtr oldpname, StringPtr newpname,
- StringPtr prefix, StringPtr suffix)
- {
- Str255 ofn, nfn;
- long offset;
-
- BlockMove(fname + 1, gText, (gLen = fname[0]));
- for (offset = 0;;) {
- pcpy(ofn, prefix); pcat(ofn, oldpname); pcat(ofn, suffix);
- pcpy(nfn, prefix); pcat(nfn, newpname); pcat(nfn, suffix);
- BlockMove(ofn + 1, gFText, (gFLen = ofn[0]));
- BlockMove(nfn + 1, gRText, (gRLen = nfn[0]));
- MyFindText(&offset);
- if (offset >= gLen) break;
- MyReplaceText(&offset);
- }
- BlockMove(gText, fname + 1, (fname[0] = gLen));
- }
-
- static void CreatePart(WindowPtr window)
- {
- ControlHandle ctl, acc;
- Rect arr;
- Str63 oldPartName, newPartName;
- Str63 fileName, oldFileName, directoryName, errstr;
- Str255 pstr, qstr;
- Str31 oldCreator, newCreator;
- StringPtr pp;
- short file, refNum, oldRes, os, ns, dd, hs, oo, rn, rr, gl;
- short deskVRefNum, vers, ii, len, numViews, ctlref;
- long ll, deskDirID;
- OSErr err, eee;
- long offset, oldoffset, folderDirID, count;
- FSSpec fss;
- Boolean brk, atg68k, atgppc, atgfat, doit;
- CInfoPBRec block;
- StringHandle sh;
- Handle hh, h2;
- OSType ctyp, ttyp, sft, sft2;
- DInfo dinfo;
- FInfo finfo;
- Handle di, fi, aa, date;
- CInfoPBRec pb;
- TreeObjHndl wfmt, wf;
-
- static StandardFileReply reply;
- static char gt[2048], gft[512], grt[512];
-
- gText = gt;
- gFText = gft;
- gRText = grt;
-
- sh = GetString(5000);
-
- gDataSetBase = 5000;
- CNum2Ctl(window, kWhichDataSet, &ctl);
- if (ctl) {
- ii = GetControlValue(ctl);
- switch (ii) {
- case 1:
- gDataSetBase = 5000;
- break;
- case 2:
- gDataSetBase = 10000;
- break;
- default:
- gDataSetBase = 10000 + 1000 * (ii - 2);
- break;
- }
- }
-
- pcpy(newPartName, *sh);
- newPartName[1] = newPartName[0] - 1;
- pcpy(oldPartName, newPartName + 1);
-
- VisCNum2Ctl(window, kOldClassName, &ctl);
- if (ctl) pcpy(oldPartName, (*ctl)->contrlTitle);
-
- VisCNum2Ctl(window, kNewClassName, &ctl);
- CTEGetPStr(ctl, newPartName);
-
- pcpy(reply.sfFile.name, newPartName);
- VisCNum2Ctl(window, kNewFolderName, &ctl);
- if (ctl) pcpy(reply.sfFile.name, (*ctl)->contrlTitle);
-
- if (!DisplayPutFile(&reply)) return;
- fss = reply.sfFile;
-
- DoSetCursor(*GetCursor(watchCursor));
-
- DoDrawControls(window, false);
- SetPort(window);
-
- err = DirCreate(fss.vRefNum, fss.parID, fss.name, &folderDirID);
- if (err) { pcpy(errstr, "\p### AAA err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (err) return;
-
- gFSSpec[gResolveIndx = 0].fss = (FSSpec **)NewHandle(sizeof(FSSpec));
- if (!gFSSpec[gResolveIndx].fss) DebugStr("\p#1: Not enough memory for jack...");
- BlockMove(&fss, *gFSSpec[gResolveIndx].fss, sizeof(FSSpec));
- pcpy(gFSSpec[gResolveIndx++].oldName, oldPartName);
-
- di = Get1Resource('dINO', gDataSetBase);
- if (di) {
- BlockMove(*di, &dinfo, sizeof(DInfo));
-
- dinfo.frLocation.h = 0;
- dinfo.frLocation.v = 0;
- if (
- !FindFolder(kOnSystemDisk, kDesktopFolderType,
- kDontCreateFolder, &deskVRefNum, &deskDirID)
- ) {
- if (deskVRefNum == fss.vRefNum) {
- if (deskDirID == fss.parID) {
- dinfo.frLocation.h = -30000;
- dinfo.frLocation.v = -30000;
- }
- }
- }
- SetDInfo(fss.vRefNum, fss.parID, fss.name, &dinfo);
- }
-
- date = Get1Resource('date', gDataSetBase);
- if (date) {
- pb.hFileInfo.ioNamePtr = fss.name;
- pb.hFileInfo.ioVRefNum = fss.vRefNum;
- pb.hFileInfo.ioDirID = fss.parID;
- pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
- if (!PBGetCatInfoSync(&pb)) {
- pb.hFileInfo.ioFlCrDat = ((long *)(*date))[0];
- pb.hFileInfo.ioFlMdDat = ((long *)(*date))[1];
- pb.hFileInfo.ioDirID = fss.parID;
- PBSetCatInfoSync(&pb);
- }
- }
-
- fss.parID = folderDirID; // Now we're inside our new project folder.
-
- DisplayControlSet(window, 'DUM1', kwHideAll);
- CNum2Ctl(window, kAboutCtlArea, &acc);
- if (acc) {
- arr = (*acc)->contrlRect;
- EraseRect(&arr);
- InvalRect(&arr);
- }
- DisplayControlSet(window, 'DUM2', kwShowAll);
-
- for (brk = 0, file = gDataSetBase + 1;
- file < gDataSetBase + 4999;
- file++) { /* Loop for all files for project. */
-
- date = Get1Resource('date', file);
-
- sh = GetString(file);
- if (!sh) break; // No more files.
- pcpy(fileName, *sh);
-
- if (fileName[1] == ':') {
- pp = fileName + 1;
- pp[0] = fileName[0] - 1;
-
- block.dirInfo.ioDrParID = fss.parID;
- for (;;) {
- if (!pp[0]) break;
- if (pp[1] != ':') break;
- pp[1] = pp[0] - 1;
- ++pp;
- SetMem(&block, 0, sizeof(CInfoPBRec));
- block.dirInfo.ioNamePtr = directoryName;
- block.dirInfo.ioDrParID = fss.parID;
- block.dirInfo.ioVRefNum = fss.vRefNum;
- block.dirInfo.ioFDirIndex = -1;
- block.dirInfo.ioDrDirID = block.dirInfo.ioDrParID;
- if (PBGetCatInfo(&block, false)) return;
- }
- fss.parID = block.dirInfo.ioDrParID;
-
- if (pp[0]) {
- pcpy(fss.name, pp);
- err = DirCreate(fss.vRefNum, fss.parID, pp, &folderDirID);
- if (err) { pcpy(errstr, "\p### BBB err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (err == dupFNErr) {
- SysBeep(1);
- }
- gFSSpec[gResolveIndx].fss = (FSSpec **)NewHandle(sizeof(FSSpec));
- if (!gFSSpec[gResolveIndx].fss) DebugStr("\p#2: Not enough memory for jack...");
- if (gFSSpec[gResolveIndx].fss) {
- BlockMove(&fss, *gFSSpec[gResolveIndx].fss, sizeof(FSSpec));
- pcpy(gFSSpec[gResolveIndx++].oldName, fileName);
- }
-
- di = Get1Resource('dINO', file);
- if (di) {
- BlockMove(*di, &dinfo, sizeof(DInfo));
- eee = SetDInfo(fss.vRefNum, fss.parID, fss.name, &dinfo);
- }
-
- if (date) {
- pb.hFileInfo.ioNamePtr = fss.name;
- pb.hFileInfo.ioVRefNum = fss.vRefNum;
- pb.hFileInfo.ioDirID = fss.parID;
- pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
- if (!PBGetCatInfoSync(&pb)) {
- pb.hFileInfo.ioFlCrDat = ((long *)(*date))[0];
- pb.hFileInfo.ioFlMdDat = ((long *)(*date))[1];
- pb.hFileInfo.ioDirID = fss.parID;
- PBSetCatInfoSync(&pb);
- }
- }
-
- if (!err) fss.parID = folderDirID;
- }
- continue;
- }
-
- #if 0
- gText = gt;
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.c");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.cpp");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\pInit.cpp");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.h");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\pDef.h");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.r");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.rsrc");
- UpdateFileName(fileName, oldPartName, newPartName, "\pC", "\p.c");
- UpdateFileName(fileName, oldPartName, newPartName, "\pCP", "\p.cpp");
- UpdateFileName(fileName, oldPartName, newPartName, "\pCP", "\pStubs.cpp");
-
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.µ");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.buildxhxih");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.idl");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.xh");
- UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p.xih");
- // UpdateFileName(fileName, oldPartName, newPartName, "\p", "\p");
-
- for (ii = 6001;; ii += 2) {
- VisCNum2Ctl(window, ii, &ctl);
- if (!ctl) break;
- pcpy(pstr, (*ctl)->contrlTitle);
- VisCNum2Ctl(window, ii + 1, &ctl);
- if (!ctl) break;
- pcpy(qstr, (*ctl)->contrlTitle);
- if (pstr[0] + qstr[0] > 0)
- UpdateFileName(fileName, oldPartName, newPartName, pstr, qstr);
- }
- #endif
-
- pcpy(oldFileName, fileName);
- gText = gt;
- BlockMove(fileName + 1, gText, (gLen = fileName[0]));
- for (offset = 0;;) {
- BlockMove(oldPartName + 1, gFText, (gFLen = oldPartName[0]));
- BlockMove(newPartName + 1, gRText, (gRLen = newPartName[0]));
- MyFindText(&offset);
- if (offset >= gLen) break;
- MyReplaceText(&offset);
- }
- BlockMove(gText, fileName + 1, (fileName[0] = gLen));
- /* This is now the name of the file, with HelloPart portion replaced. */
-
- CNum2Ctl(window, 201, &ctl); /* writing to... controls. */
- if (!ctl) DebugStr("\pctl is nil @ A");
- pcpy(pstr, (*ctl)->contrlTitle);
- pcat(pstr, fileName);
- CNum2Ctl(window, 202, &ctl);
- if (!ctl) DebugStr("\pctl is nil @ B");
- pcat(pstr, (*ctl)->contrlTitle);
- CNum2Ctl(window, 200, &ctl);
- if (!ctl) DebugStr("\pctl is nil @ C");
- SetStyledCTitle(ctl, pstr);
-
- hh = Get1Resource('cTYP', file);
- if (!hh) DebugStr("\presource not found @ A");
- BlockMove(*hh, &ctyp, sizeof(OSType));
- hh = Get1Resource('tTYP', file);
- if (!hh) DebugStr("\presource not found @ B");
- BlockMove(*hh, &ttyp, sizeof(OSType));
-
- pcpy(fss.name, fileName);
- err = HCreate(fss.vRefNum, fss.parID, fss.name, ctyp, ttyp);
- if (err) { pcpy(errstr, "\p### CCC err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (err) {
- DisplayControlSet(window, 'DUM2', kwHideAll);
- CNum2Ctl(window, kAboutCtlArea, &acc);
- if (acc) {
- arr = (*acc)->contrlRect;
- EraseRect(&arr);
- InvalRect(&arr);
- }
- DisplayControlSet(window, 'DUM1', kwShowAll);
- return;
- }
-
- gFSSpec[gResolveIndx].fss = (FSSpec **)NewHandle(sizeof(FSSpec));
- if (!gFSSpec[gResolveIndx].fss) DebugStr("\p#3: Not enough memory for jack...");
- if (gFSSpec[gResolveIndx].fss) {
- BlockMove(&fss, *gFSSpec[gResolveIndx].fss, sizeof(FSSpec));
- pcpy(gFSSpec[gResolveIndx++].oldName, oldFileName);
- }
-
- fi = Get1Resource('fINO', file);
- if (fi) {
- BlockMove(*fi, &finfo, sizeof(FInfo));
- eee = HSetFInfo(fss.vRefNum, fss.parID, fss.name, &finfo);
- }
-
- err = HOpenDF(fss.vRefNum, fss.parID, fileName, fsRdWrPerm, &refNum);
- if (err) { pcpy(errstr, "\p### DDD err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (err) {
- //wrong FSClose(refNum);
-
- CNum2Ctl(window, kAboutCtlArea, &acc);
- if (acc) {
- arr = (*acc)->contrlRect;
- EraseRect(&arr);
- InvalRect(&arr);
- }
- DisplayControlSet(window, 'DUM2', kwHideAll);
- CNum2Ctl(window, kAboutCtlArea, &acc);
- if (acc) {
- arr = (*acc)->contrlRect;
- EraseRect(&arr);
- InvalRect(&arr);
- }
- DisplayControlSet(window, 'DUM1', kwShowAll);
- return;
- }
-
- err = SetFPos(refNum, fsFromStart, 0);
- if (err) { pcpy(errstr, "\p### EEE err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (err) {
- FSClose(refNum);
- DisplayControlSet(window, 'DUM2', kwHideAll);
- CNum2Ctl(window, kAboutCtlArea, &acc);
- if (acc) {
- arr = (*acc)->contrlRect;
- EraseRect(&arr);
- InvalRect(&arr);
- }
- DisplayControlSet(window, 'DUM1', kwShowAll);
- return;
- }
-
- atg68k = atgppc = atgfat = 0;
-
- hh = Get1Resource('dFRK', file);
- if (!hh) {
- err = ResError();
- DebugStr("\presource not found @ C");
- }
-
- DetachResource(hh);
- gLen = GetHandleSize(hh);
- SetHandleSize(hh, gLen + 0X20000L); // Give the buffer some slop, please
- err = MemError();
- if (err) {
- DebugStr("\pmem error @ C2");
- }
- HLock(hh);
-
- gText = *hh; // Careful -- "static" work area pointing to a handle that will go away.
-
- if ((ttyp == 'MMPR') || (ttyp == 'PRØJ')) { // Metrowerks.
-
- pcpy(pstr, oldPartName); pcat(pstr, "\p.68k copy"); // AppsToGo
- pcpy(qstr, newPartName); pcat(qstr, "\p.68k copy");
- atg68k = UpdateHandle(hh, pstr, qstr, false);
-
- pcpy(pstr, oldPartName); pcat(pstr, "\p.PPC copy"); // AppsToGo
- pcpy(qstr, newPartName); pcat(qstr, "\p.PPC copy");
- atgppc = UpdateHandle(hh, pstr, qstr, false);
-
- pcpy(pstr, oldPartName); pcat(pstr, "\p.68k"); // AppsToGo FAT build.
- pcpy(qstr, newPartName); pcat(qstr, "\p.68k");
- atgfat = UpdateHandle(hh, pstr, qstr, false);
-
- pcpy(pstr, oldPartName); pcat(pstr, "\p.c"); // OpenDoc.
- pcpy(qstr, newPartName); pcat(qstr, "\p.c");
- UpdateHandle(hh, pstr, qstr, false);
- pcpy(pstr, oldPartName); pcat(pstr, "\p.cpp");
- pcpy(qstr, newPartName); pcat(qstr, "\p.cpp");
- UpdateHandle(hh, pstr, qstr, false);
- pcpy(pstr, oldPartName); pcat(pstr, "\pInit.cpp");
- pcpy(qstr, newPartName); pcat(qstr, "\pInit.cpp");
- UpdateHandle(hh, pstr, qstr, false);
- pcpy(pstr, oldPartName); pcat(pstr, "\p.h");
- pcpy(qstr, newPartName); pcat(qstr, "\p.h");
- UpdateHandle(hh, pstr, qstr, false);
- pcpy(pstr, oldPartName); pcat(pstr, "\pDef.h");
- pcpy(qstr, newPartName); pcat(qstr, "\pDef.h");
- UpdateHandle(hh, pstr, qstr, false);
- pcpy(pstr, oldPartName); pcat(pstr, "\p.r");
- pcpy(qstr, newPartName); pcat(qstr, "\p.r");
- UpdateHandle(hh, pstr, qstr, false);
- pcpy(pstr, oldPartName); pcat(pstr, "\p.rsrc");
- pcpy(qstr, newPartName); pcat(qstr, "\p.rsrc");
- UpdateHandle(hh, pstr, qstr, false);
- pcpy(pstr, "\pC"); pcat(pstr, oldPartName); pcat(pstr, "\p.c");
- pcpy(qstr, "\pC"); pcat(qstr, newPartName); pcat(qstr, "\p.c");
- UpdateHandle(hh, pstr, qstr, false);
- pcpy(pstr, "\pCP"); pcat(pstr, oldPartName); pcat(pstr, "\p.cpp");
- pcpy(qstr, "\pCP"); pcat(qstr, newPartName); pcat(qstr, "\p.cpp");
- UpdateHandle(hh, pstr, qstr, false);
- pcpy(pstr, "\pCP"); pcat(pstr, oldPartName); pcat(pstr, "\pStubs.cpp");
- pcpy(qstr, "\pCP"); pcat(qstr, newPartName); pcat(qstr, "\pStubs.cpp");
- UpdateHandle(hh, pstr, qstr, false);
-
- for (ii = 6001;; ii += 2) {
- VisCNum2Ctl(window, ii, &ctl);
- if (!ctl) break;
- len = (*ctl)->contrlTitle[0];
- pcpy(pstr, (*ctl)->contrlTitle); pcat(pstr, oldPartName);
- pcpy(qstr, (*ctl)->contrlTitle); pcat(qstr, newPartName);
- VisCNum2Ctl(window, ii + 1, &ctl);
- if (!ctl) break;
- pcat(pstr, (*ctl)->contrlTitle);
- pcat(qstr, (*ctl)->contrlTitle);
- len += (*ctl)->contrlTitle[0];
- if (len) UpdateHandle(hh, pstr, qstr, false);
- }
- }
-
- if (ttyp == 'TEXT') {
- for (offset = 0;;) {
- BlockMove(oldPartName + 1, gFText, (gFLen = oldPartName[0]));
- BlockMove(newPartName + 1, gRText, (gRLen = newPartName[0]));
- MyFindText(&offset);
- if (offset >= gLen) break;
- MyReplaceText(&offset);
- }
- VisCNum2Ctl(window, kNewCompanyName, &ctl);
- if (ctl) {
- CTEGetPStr(ctl, qstr);
- VisCNum2Ctl(window, kOldCompanyName, &ctl);
- if (ctl) {
- for (offset = 0;;) {
- pcpy(pstr, (*ctl)->contrlTitle);
- BlockMove(pstr + 1, gFText, (gFLen = pstr[0]));
- BlockMove(qstr + 1, gRText, (gRLen = qstr[0]));
- MyFindText(&offset);
- if (offset >= gLen) break;
- MyReplaceText(&offset);
- }
- }
- }
-
- oldCreator[0] = 0;
- newCreator[0] = 0;
- VisCNum2Ctl(window, kAppWannabeCreator, &ctl);
- if (ctl) {
- CTEGetPStr(ctl, pstr);
- pcpy(newCreator, pstr);
- pcpy(qstr, "\p'");
- pcat(qstr, pstr);
- pcat(qstr, "\p'");
- VisCNum2Ctl(window, kOldAppWannabeCreator, &ctl);
- if (ctl) {
- pcpy(pstr, (*ctl)->contrlTitle);
- oldCreator[0] = sizeof(OSType);
- BlockMove(pstr + 2, oldCreator + 1, sizeof(OSType));
- for (offset = 0;;) {
- BlockMove(pstr + 1, gFText, (gFLen = pstr[0]));
- BlockMove(qstr + 1, gRText, (gRLen = qstr[0]));
- MyFindText(&offset);
- if (offset >= gLen) break;
- oldoffset = offset;
- MyReplaceText(&offset);
- BlockMove(gRText, gText + oldoffset, gRLen); // Use source case.
- }
- }
- }
- VisCNum2Ctl(window, kAppWannabeDefDoc, &ctl);
- if (ctl) {
- CTEGetPStr(ctl, pstr);
- pcpy(qstr, "\p'");
- pcat(qstr, pstr);
- pcat(qstr, "\p'");
- VisCNum2Ctl(window, kOldAppWannabeDefDoc, &ctl);
- if (ctl) {
- pcpy(pstr, (*ctl)->contrlTitle);
- for (offset = 0;;) {
- BlockMove(pstr + 1, gFText, (gFLen = pstr[0]));
- BlockMove(qstr + 1, gRText, (gRLen = qstr[0]));
- MyFindText(&offset);
- if (offset >= gLen) break;
- oldoffset = offset;
- MyReplaceText(&offset);
- BlockMove(gRText, gText + oldoffset, gRLen); // Use source case.
- }
- }
- }
- }
-
- count = gLen;
- err = FSWrite(refNum, &count, gText);
- if (err) { pcpy(errstr, "\p### FFF err = $"); pcathex(errstr, err); DebugStr(errstr); }
-
- DisposeHandle(hh);
- gText = gt; // gText is safe again -- done being careful.
-
- FSClose(refNum); // Done with data fork.
-
- refNum = kInvalRefNum;
- HCreateResFile(fss.vRefNum, fss.parID, fileName);
- err = ResError();
- if (err) { pcpy(errstr, "\p### GGG err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (!err) {
- refNum = HOpenResFile(fss.vRefNum, fss.parID, fileName, fsRdWrPerm);
- err = ResError();
- if (!err) CloseResFile(refNum); // We don't want to deal with it as a resource fork.
- if (err)
- { pcpy(errstr, fileName); pcat(errstr, "\p### HHH err = $"); pcathex(errstr, err); DebugStr(errstr); }
- }
-
- if (err) { pcpy(errstr, "\p### III err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (!err) {
- hh = Get1Resource('rFRK', file);
- if (!hh) DebugStr("\presource not found @ D");
- HLock(hh);
- err = HOpenRF(fss.vRefNum, fss.parID, fileName, fsRdWrPerm, &refNum);
- // SetFPos(refNum, fsFromStart, 0);
- if (err) { pcpy(errstr, "\p### JJJ err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (!err) {
- count = GetHandleSize(hh);
- err = FSWrite(refNum, &count, *hh);
- if (err) { pcpy(errstr, "\p### KKK err = $"); pcathex(errstr, err); DebugStr(errstr); }
- SetEOF(refNum, count);
- FSClose(refNum);
- }
- DetachResource(hh);
- DisposeHandle(hh);
- }
-
- if (err) { pcpy(errstr, "\p### LLL err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (!err) {
- oldRes = CurResFile();
- refNum = HOpenResFile(fss.vRefNum, fss.parID, fileName, fsRdWrPerm);
- UseResFile(refNum);
-
- if (finfo.fdFlags & kIsAlias) {
- aa = Get1Resource('alis', 0);
- if (aa) {
- DetachResource(aa);
- gAlias[gResolveIndx - 1] = (AliasHandle)aa;
- }
- }
-
- VisCNum2Ctl(window, kOldCompanyName, &ctl);
- if (ctl) {
- pcpy(pstr, (*ctl)->contrlTitle);
- VisCNum2Ctl(window, kNewCompanyName, &ctl);
- if (ctl) {
- CTEGetPStr(ctl, qstr);
- pcat(pstr, "\p:");
- pcat(qstr, "\p:");
- FixNMAPs(pstr, qstr);
- FixNMAPs(oldPartName, newPartName);
- }
- }
-
-
- VisCNum2Ctl(window, kNewCompanyName, &ctl);
- if (ctl) {
- if ((ttyp == 'rsrc') || (ttyp == 'RSRC')) {
- if ((ctyp == 'RSED') || (ctyp == 'Doug')) {
- hh = Get1Resource('cfrg', 0);
- if ((!gNoReplace) && (hh)) {
- hs = GetHandleSize(hh);
-
- pcpy(pstr, (StringPtr)((*hh) + 0x20 + 0x2A));
- pcpy(qstr, pstr);
-
-
-
- gFLen = gRLen = 0;
- BlockMove(qstr + 1, gText, (gLen = qstr[0]));
- VisCNum2Ctl(window, kOldCompanyName, &ctl);
- if (ctl) {
- pcpy(qstr, (*ctl)->contrlTitle);
- BlockMove(qstr + 1, gFText, (gFLen = qstr[0]));
- }
- VisCNum2Ctl(window, kNewCompanyName, &ctl);
- if (ctl) {
- CTEGetPStr(ctl, qstr);
- BlockMove(qstr + 1, gRText, (gRLen = qstr[0]));
- }
- if ((gFLen) && (gRLen)) {
- for (offset = 0;;) {
- MyFindText(&offset);
- if (offset >= gLen) break;
- MyReplaceText(&offset);
- }
- for (offset = 0;;) {
- BlockMove(oldPartName + 1, gFText, (gFLen = oldPartName[0]));
- BlockMove(newPartName + 1, gRText, (gRLen = newPartName[0]));
- MyFindText(&offset);
- if (offset >= gLen) break;
- MyReplaceText(&offset);
- }
- BlockMove(gText, qstr + 1, (qstr[0] = gLen));
- }
-
- if (pcmp(pstr, qstr)) {
- SetHandleSize(hh, hs + 0x1000);
-
- // VisCNum2Ctl(window, kNewCompanyName, &ctl);
- // CTEGetPStr(ctl, qstr);
- // pcatchr(qstr, ':', 2);
- // pcat(qstr, newPartName);
-
- os = (0x20 + 0x2A + pstr[0] + 1 + 0x03) & 0xFFFC;
- ns = (0x20 + 0x2A + qstr[0] + 1 + 0x03) & 0xFFFC;
- dd = ns - os;
- BlockMove(*hh + os, *hh + ns, hs);
- pcpy((StringPtr)((*hh) + 0x20 + 0x2A), qstr);
- *(short *)((*hh) + 0x20 + 0x28) = ns - 0x20;
- hs += dd; // Guaranteed to still be long-aligned, since dd is...
-
- pcpy(pstr, (StringPtr)((*hh) + ns + 0x2A));
- pcpy(qstr, pstr);
-
- BlockMove(qstr + 1, gText, (gLen = qstr[0]));
- for (offset = 0;;) {
- BlockMove(oldPartName + 1, gFText, (gFLen = oldPartName[0]));
- BlockMove(newPartName + 1, gRText, (gRLen = newPartName[0]));
- MyFindText(&offset);
- if (offset >= gLen) break;
- MyReplaceText(&offset);
- }
- BlockMove(gText, qstr + 1, (qstr[0] = gLen));
-
-
- oo = ns + 0x2A;
- os = (oo + pstr[0] + 1 + 0x03) & 0xFFFC;
- ns = (oo + qstr[0] + 1 + 0x03) & 0xFFFC;
- pcpy((StringPtr)((*hh) + oo), qstr);
- *(short *)((*hh) + oo - sizeof(short)) = ns - oo + 0x2A;
-
- SetHandleSize(hh, ns);
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
- }
- }
-
- if (ttyp == 'MMPR') { // Update Metrowerks PPC project library name / creator.
- if (ctyp == 'MPCC') {
- hh = Get1Resource('pVer', 0);
- if ((!gNoReplace) && (hh)) {
- if (GetHandleSize(hh) == 2) {
- vers = **(short **)hh;
- if ((vers == 2) || (vers == 3)) {
- hh = Get1Resource('pref', 805);
- if (hh) {
- BlockMove(*hh + 4, qstr, GetHandleSize(hh) - 4);
- pstr[0] = qstr[0];
- for (;;) {
- if (!qstr[0]) break;
- if (qstr[qstr[0]] == ':') break;
- qstr[0]--;
- }
- pstr[0] -= qstr[0];
- BlockMove(qstr + 1 + qstr[0], pstr + 1, pstr[0]);
- UpdateFileName(pstr, oldPartName, newPartName, "\p", "\p");
- pcat(qstr, pstr);
-
- // pcat(qstr, newPartName);
- // if ((atgppc) && (!atgfat)) pcat(qstr, "\p.PPC");
- // if (atgfat) pcat(qstr, "\p.FAT");
-
- BlockMove(qstr, *hh + 4, qstr[0] + 1);
- VisCNum2Ctl(window, kAppWannabeCreator, &ctl);
- if (ctl) {
- CTEGetPStr(ctl, qstr);
- BlockMove(qstr + 1, *hh + 0x24, sizeof(OSType));
- }
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
- }
- }
- }
-
-
- if (ttyp == 'MMPR') { // Update Metrowerks PPC PEF name.
- if (ctyp == 'MPCC') {
- hh = Get1Resource('pVer', 0);
- if ((!gNoReplace) && (hh)) {
- if (GetHandleSize(hh) == 2) {
- vers = **(short **)hh;
- if ((vers == 2) || (vers == 3)) {
- hh = Get1Resource('pref', 807);
- if (hh) {
- BlockMove(*hh + 18, qstr, GetHandleSize(hh) - 18);
- pstr[0] = qstr[0];
- for (;;) {
- if (!qstr[0]) break;
- if (qstr[qstr[0]] == ':') break;
- qstr[0]--;
- }
- pstr[0] -= qstr[0];
- BlockMove(qstr + 1 + qstr[0], pstr + 1, pstr[0]);
- UpdateFileName(pstr, oldPartName, newPartName, "\p", "\p");
- pcat(qstr, pstr);
-
- BlockMove(qstr, *hh + 18, qstr[0] + 1);
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
- }
- }
- }
-
- CNum2Ctl(window, kOpenDoc, &ctl);
- if (ctl) { // This code is just for OpenDoc support.
- if (ttyp == 'MMPR') { // Update Metrowerks PPC project link names.
- if (ctyp == 'MPCC') {
- hh = Get1Resource('pVer', 0);
- if ((!gNoReplace) && (hh)) {
- if (GetHandleSize(hh) == 2) {
- vers = **(short **)hh;
- if ((vers == 2) || (vers == 3)) {
- hh = Get1Resource('pref', 804);
- if (hh) {
- pcpy(qstr, newPartName);
- pcat(qstr, "\pCFMInit\0");
- BlockMove(qstr + 1, *hh + 0x04, qstr[0] + 1);
- pcpy(qstr, newPartName);
- pcat(qstr, "\pSOMInit\0");
- BlockMove(qstr + 1, *hh + 0x44, qstr[0] + 1);
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
- }
- }
- }
- }
-
- if (ttyp == 'MMPR') { // Update Metrowerks 68k project library name / creator.
- if (ctyp == 'MMCC') {
- hh = Get1Resource('pVer', 0);
- if ((!gNoReplace) && (hh)) {
- if (GetHandleSize(hh) == 2) {
- vers = **(short **)hh;
- if ((vers == 2) || (vers == 3)) {
- hh = Get1Resource('pref', 5);
- if (hh) {
- BlockMove(*hh + 4, qstr, GetHandleSize(hh) - 4);
- pstr[0] = qstr[0];
- for (;;) {
- if (!qstr[0]) break;
- if (qstr[qstr[0]] == ':') break;
- qstr[0]--;
- }
- pstr[0] -= qstr[0];
- BlockMove(qstr + 1 + qstr[0], pstr + 1, pstr[0]);
- UpdateFileName(pstr, oldPartName, newPartName, "\p", "\p");
- pcat(qstr, pstr);
-
- // pcat(qstr, newPartName);
- // if (atg68k) pcat(qstr, "\p.68k");
- BlockMove(qstr, *hh + 4, qstr[0] + 1);
-
- VisCNum2Ctl(window, kAppWannabeCreator, &ctl);
- if (ctl) {
- CTEGetPStr(ctl, qstr);
- BlockMove(qstr + 1, *hh + 0x44, sizeof(OSType));
- }
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
- }
- }
- }
-
- if (ttyp == 'PROJ') { // Update THINK project library name / creator.
- if (ctyp == 'KAHL') {
- hh = Get1Resource('KIND', 0);
- if ((!gNoReplace) && (hh)) {
- BlockMove(newPartName, *hh + 0x10C, newPartName[0] + 1);
- VisCNum2Ctl(window, kAppWannabeCreator, &ctl);
- if (ctl) {
- CTEGetPStr(ctl, qstr);
- BlockMove(qstr + 1, *hh + 0x150, sizeof(OSType));
- }
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
-
- if ((ttyp == 'rsrc') || (ttyp == 'RSRC')) {
-
- if (!gNoReplace) {
- VisCNum2Ctl(window, kMacAppViews, &ctl);
- if (ctl) {
- for (numViews = Count1Resources('View'); numViews; --numViews) {
- hh = Get1IndResource('View', numViews);
- if (hh) {
- doit = false;
- for (ii = kMacAppViews + 1;; ii += 2) {
- VisCNum2Ctl(window, ii, &ctl);
- if (!ctl) break;
- len = (*ctl)->contrlTitle[0];
- pcpy(pstr, (*ctl)->contrlTitle); pcat(pstr, oldPartName);
- pcpy(qstr, (*ctl)->contrlTitle); pcat(qstr, newPartName);
- VisCNum2Ctl(window, ii + 1, &ctl);
- if (!ctl) break;
- pcat(pstr, (*ctl)->contrlTitle);
- pcat(qstr, (*ctl)->contrlTitle);
- len += (*ctl)->contrlTitle[0];
- if (len) doit |= UpdateHandle(hh, pstr, qstr, true);
- }
- if (doit) {
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
- }
- }
-
- doit = false;
- CNum2Ctl(window, kOpenDoc, &ctl);
- if (ctl) doit = true;
- VisCNum2Ctl(window, kAppWannabeCreator, &ctl);
- if (ctl) doit = true;
- if (gNoReplace) doit = false;
-
- if (doit) {
- for (rr = 0; rr < 2; ++rr) {
- switch (rr) {
- case 0: sft = 'MENU'; break;
- case 1: sft = 'STR#'; break;
- }
- for (rn = Count1Resources(sft); rn; --rn) {
- switch (rr) {
- case 0: oo = 0x0E; break;
- case 1: oo = 0x02; break;
- }
- hh = Get1IndResource(sft, rn);
- if ((!gNoReplace) && (hh)) {
- for (;;) {
- hs = GetHandleSize(hh);
- if (oo >= hs) break;
- pcpy((StringPtr)gText, (StringPtr)((*hh) + oo));
- gLen = gl = (gText[0] + 1);
- for (offset = 0;;) {
- BlockMove(oldPartName + 1, gFText, (gFLen = oldPartName[0]));
- BlockMove(newPartName + 1, gRText, (gRLen = newPartName[0]));
- MyFindText(&offset);
- if (offset >= gLen) break;
- MyReplaceText(&offset);
- }
- gText[0] = gLen - 1;
- SetHandleSize(hh, 0x10000L);
- BlockMove(
- (*hh) + oo + gl,
- (*hh) + oo + gl + (gLen - gl),
- hs
- );
- SetHandleSize(hh, hs + (gLen - gl));
- pcpy((StringPtr)((*hh) + oo), (StringPtr)gText);
- oo += gLen;
- }
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
- }
-
- CNum2Ctl(window, kOpenDoc, &ctl);
- if (ctl) {
- ctlref = GetControlReference(ctl);
- if (ctlref) {
- hh = Get1Resource('DITL', ctlref);
- if ((!gNoReplace) && (hh)) {
- pcpy (pstr, newPartName);
- pcatchr(pstr, ' ', 40);
- BlockMove(pstr + 1, (*hh) + 0x20, 40);
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
-
- if (!gNoReplace) {
- VisCNum2Ctl(window, kAppWannabeCreator, &ctl);
-
- if (ctl) { // This code is just for AppsToGo support.
-
- hh = Get1Resource('BNDL', 128);
- if (hh) {
- CTEGetPStr(ctl, qstr);
- BlockMove(qstr + 1, *hh + 0x00, sizeof(OSType));
- ChangedResource(hh);
- WriteResource(hh);
- }
-
- oldCreator[0] = 0;
- CTEGetPStr(ctl, qstr);
- VisCNum2Ctl(window, kOldAppWannabeCreator, &ctl);
- if (ctl) {
- pcpy(pstr, (*ctl)->contrlTitle);
- BlockMove(pstr + 2, oldCreator + 1, (oldCreator[0] = sizeof(OSType)));
- }
-
- if (oldCreator[0]) {
- hh = Get1Resource('STR#', 128);
- if (hh) {
- UpdateHandle(hh, oldCreator, qstr, true);
- ChangedResource(hh);
- WriteResource(hh);
- }
-
- BlockMove(oldCreator + 1, &sft, sizeof(OSType));
- BlockMove(newCreator + 1, &sft2, sizeof(OSType));
-
- hh = Get1Resource(sft, 0);
- if (hh) DetachResource(hh);
- h2 = Get1Resource(sft, 0);
- if (h2) {
- RemoveResource(h2);
- DisposeHandle(h2);
- }
-
- if (hh) {
- pcpy(pstr, (StringPtr)(*hh));
- pp = pstr + oldPartName[0];
- pp[0] = pstr[0] - oldPartName[0];
- pcpy(qstr, newPartName);
- pcat(qstr, pp);
- pcpy(pstr, (StringPtr)(*hh));
- UpdateHandle(hh, pstr, qstr, true);
-
- AddResource(hh, sft2, 0, nil);
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
-
- pstr[0] = qstr[0] = 0;
- VisCNum2Ctl(window, kAppWannabeDefDoc, &ctl);
- if (ctl) CTEGetPStr(ctl, qstr);
- VisCNum2Ctl(window, kOldAppWannabeDefDoc, &ctl);
- if (ctl) {
- pstr[0] = sizeof(OSType);
- BlockMove((*ctl)->contrlTitle + 2, pstr + 1, sizeof(OSType));
- }
- if ((pstr[0]) && (qstr[0])) {
- hh = Get1Resource('WFMT', 128);
- if (hh) {
- BlockMove(pstr + 1, &sft, sizeof(OSType));
- wfmt = NewRootObj(ROOTOBJ, 0);
- HReadTree(wfmt, hh);
- for (ii = 0; ii < (*wfmt)->numChildren; ++ii) {
- wf = GetChildHndl(wfmt, ii);
- if (mDerefWFMT(wf)->sfType == sft) {
- BlockMove(qstr + 1, &sft, sizeof(OSType));
- mDerefWFMT(wf)->sfType = sft;
- break;
- }
- }
- SetHandleSize(hh, 0); /* Should already be 0. */
- HWriteTree(wfmt, hh);
- DisposeObjAndOffspring(wfmt);
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
-
- VisCNum2Ctl(window, kAppWannabeDefDoc, &ctl);
- if (ctl) {
- hh = Get1Resource('FREF', 129);
- if (hh) {
- CTEGetPStr(ctl, qstr);
- BlockMove(qstr + 1, *hh + 0x00, sizeof(OSType));
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- VisCNum2Ctl(window, kAppWannabeCreator, &ctl);
- if (ctl) {
- hh = Get1Resource('STR ', -16396);
- if (hh) {
- UpdateHandle(hh, oldPartName, newPartName, true);
- ChangedResource(hh);
- WriteResource(hh);
- }
- hh = Get1Resource('vers', 1);
- if (hh) {
- pcpy(pstr, (StringPtr)(*hh + 0x06 + (*hh)[6] + 1));
- pp = pstr + oldPartName[0];
- pp[0] = pstr[0] - oldPartName[0];
- pcpy(qstr, newPartName);
- pcat(qstr, pp);
- pcpy(pstr, (StringPtr)(*hh + 0x06 + (*hh)[6] + 1));
- UpdateHandle(hh, pstr, qstr, true);
- ChangedResource(hh);
- WriteResource(hh);
- }
- }
- }
- }
-
- if (date) {
- pb.hFileInfo.ioNamePtr = fss.name;
- pb.hFileInfo.ioVRefNum = fss.vRefNum;
- pb.hFileInfo.ioDirID = fss.parID;
- pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
- if (!PBGetCatInfoSync(&pb)) {
- pb.hFileInfo.ioFlCrDat = ((long *)(*date))[0];
- pb.hFileInfo.ioFlMdDat = ((long *)(*date))[1];
- pb.hFileInfo.ioDirID = fss.parID;
- eee = PBSetCatInfoSync(&pb);
- }
- }
-
- CloseResFile(refNum);
- UseResFile(oldRes);
- }
-
- if (err) { pcpy(errstr, "\p### MMM err = $"); pcathex(errstr, err); DebugStr(errstr); }
- if (err) {
- DisplayControlSet(window, 'DUM2', kwHideAll);
- CNum2Ctl(window, kAboutCtlArea, &acc);
- if (acc) {
- arr = (*acc)->contrlRect;
- EraseRect(&arr);
- InvalRect(&arr);
- }
- DisplayControlSet(window, 'DUM1', kwShowAll);
- return;
- }
-
- if (brk) break;
- }
-
- UseResFile(gAppResRef);
-
- Delay(30, &ll);
-
- DisplayControlSet(window, 'DUM2', kwHideAll);
- CNum2Ctl(window, kAboutCtlArea, &acc);
- if (acc) {
- arr = (*acc)->contrlRect;
- EraseRect(&arr);
- InvalRect(&arr);
- }
- DisplayControlSet(window, 'DUM1', kwShowAll);
- }
-
- static void FixupAliases(WindowPtr window)
- {
- short ii, jj, srcFolderPathLen, dstFolderPathLen, oldRes, res;
- AliasHandle aa;
- FSSpec **fssh, fss, targetfss;
- Str255 p1, p2;
- StringPtr pptr;
- OSErr err;
- Boolean wasChanged;
- static Str255 aliasPath, aliasName, fsPath, fsName;
-
- fssh = gFSSpec[0].fss;
- if (!fssh) return;
-
- fss = **fssh;
- if (FullPathFromFSSpec(&fss, fsPath, fsName)) return;
- dstFolderPathLen = fsPath[0] + 1;
-
- for (ii = 0; ii < gResolveIndx; ++ii) {
- aa = gAlias[ii];
- if (!aa) continue;
-
- if (FullPathFromAlias(aa, aliasPath, aliasName)) continue;
- srcFolderPathLen = aliasPath[0] - aliasName[0];
-
- for (jj = 0; jj < gResolveIndx; ++jj) {
- fssh = gFSSpec[jj].fss;
- if (!fssh) continue;
-
- fss = **fssh;
- if (FullPathFromFSSpec(&fss, fsPath, fsName)) continue;
-
- if (aliasPath[0] <= srcFolderPathLen) continue;
- if (fsPath[0] <= dstFolderPathLen) continue;
- if (pcmp(aliasName, gFSSpec[jj].oldName)) continue;
-
- p1[0] = fsPath[0] - dstFolderPathLen;
- BlockMove(fsPath + dstFolderPathLen + 1, p1 + 1, p1[0]);
- for (; p1[0]; --p1[0]) if (p1[p1[0]] == ':') break;
- pcat(p1, gFSSpec[jj].oldName);
-
- if (p1[0] > aliasPath[0]) continue;
-
- p2[0] = p1[0];
- BlockMove(aliasPath + 1 + (aliasPath[0] - p2[0]), p2 + 1, p2[0]);
-
- if (pcmp(p1, p2)) continue;
-
- fssh = gFSSpec[ii].fss;
- if (!fssh) continue;
- fss = **fssh;
-
- oldRes = CurResFile();
- res = HOpenResFile(fss.vRefNum, fss.parID, fss.name, fsRdWrPerm);
- if (ResError()) continue;
- aa = (AliasHandle)Get1Resource('alis', 0);
- if (aa) {
- pptr = fsPath;
- for (;;) {
- if (!pptr[0]) break;
- if (pptr[1] == ':') {
- err = FSMakeFSSpec(fss.vRefNum, fsRtDirID, pptr, &targetfss);
- err = UpdateAlias(&fss, &targetfss, aa, &wasChanged);
- ChangedResource((Handle)aa);
- WriteResource((Handle)aa);
- break;
- }
- pptr[1] = pptr[0] - 1;
- ++pptr;
- }
- }
- CloseResFile(res);
- UseResFile(oldRes);
- }
- }
-
- for (ii = 0; ii < gResolveIndx; ++ii) {
- aa = gAlias[ii];
- if (aa) {
- DisposeHandle((Handle)aa);
- gAlias[ii] = nil;
- }
- fssh = gFSSpec[ii].fss;
- if (fssh) {
- DisposeHandle((Handle)fssh);
- gFSSpec[ii].fss = nil;
- }
- }
-
- gResolveIndx = 0;
- }
-
- static OSErr FullPathFromAlias(AliasHandle alias, StringPtr aliasPath, StringPtr aliasName)
- {
- OSErr result;
- AliasInfoType index;
- Str255 nodeName, temp;
-
- /* Get partial pathname */
- aliasPath[0] = 0;
- index = asiAliasName;
- do
- {
- result = GetAliasInfo(alias, index, nodeName);
- if ( (result == noErr) && (nodeName[0] != 0) )
- {
- pcpy(temp, aliasPath);
- pcpy(aliasPath, "\p:");
- pcat(aliasPath, nodeName);
- pcat(aliasPath, temp);
- if (!index) pcpy(aliasName, nodeName);
- }
- ++index;
- } while ( (result != noErr) || (nodeName[0] != 0) );
-
- if (result == noErr)
- {
- /* Add volume name */
- result = GetAliasInfo(alias, asiVolumeName, nodeName);
- if ( result == noErr )
- {
- pcpy(temp, aliasPath);
- pcpy(aliasPath, nodeName);
- pcat(aliasPath, temp);
- }
- }
- return ( result );
- }
-
- static OSErr FullPathFromFSSpec(const FSSpec *spec, StringPtr fsPath, StringPtr fsName)
- {
- OSErr result;
- CInfoPBRec pb;
- Str255 nodeName, temp;
-
- fsPath[0] = 0;
-
- /* Build a full pathname down to the volume */
- pb.dirInfo.ioNamePtr = nodeName;
- pb.dirInfo.ioVRefNum = spec->vRefNum;
- pb.dirInfo.ioDrParID = spec->parID;
- do
- {
- pb.dirInfo.ioFDirIndex = -1;
- pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
- result = PBGetCatInfoSync(&pb);
- pcpy(temp, fsPath);
- pcpy(fsPath, nodeName);
- pcat(fsPath, "\p:");
- pcat(fsPath, temp);
- } while ( (result == noErr) && (pb.dirInfo.ioDrDirID != fsRtDirID) );
-
- /* add the spec's name field and we're done */
- pcat(fsPath, (StringPtr)spec->name);
-
- pcpy(fsName, (StringPtr)spec->name);
- return ( result );
- }
-
-
-
- /*****************************************************************************/
- /*****************************************************************************/
- /*****************************************************************************/
-
-
-
- // This code goes into a separate segment due to the way that PartMaker is shipped.
- // The internal version of PartMaker can create PartMaker documents. We don't
- // ship this version. To make a shippable version, do the following:
- // • Use AppsToGo Editor to delete the 'fold' entry (optional).
- // • Use ResEdit to remove the 'fold' 'BNDL' entry.
- // • Use ResEdit to remove the "AppleOnly" 'CODE' resource.
- // After the above steps, the ability to turn folders into projects has been removed.
-
- OSErr CacheFile(FSSpec out, FSSpec in, short *oldDepth, short newDepth)
- {
- OSErr err = noErr;
- short oldRes, outRes, inRes, inRef;
- long eof, date[2];
- Handle hndl;
- Boolean isFolder;
- FInfo finfo, fff;
- DInfo dinfo;
- Str255 pstr;
- CInfoPBRec pb;
-
- oldRes = CurResFile();
-
- isFolder = false;
- err = GetDInfo(in.vRefNum, in.parID, in.name, &dinfo);
- if (!err) isFolder = true;
- if (!isFolder) {
- HGetFInfo(in.vRefNum, in.parID, in.name, &finfo);
- if (finfo.fdCreator == 'MPS ') {
- if (finfo.fdType == 'OBJ ') return(noErr);
- if (finfo.fdType == 'XCOF') return(noErr);
- }
- if (finfo.fdCreator == 'MWDB') {
- if (finfo.fdType == 'MMPF') return(noErr);
- if (finfo.fdType == 'MPSY') return(noErr);
- }
- }
-
- outRes = HOpenResFile(out.vRefNum, out.parID, out.name, fsRdWrPerm);
- err = ResError();
- if (err) {
- if ((err != eofErr) && (err != fnfErr)) {
- UseResFile(oldRes);
- return(err);
- }
- HCreateResFile(out.vRefNum, out.parID, out.name);
- err = ResError();
- if (err) {
- UseResFile(oldRes);
- return(err);
- }
- outRes = HOpenResFile(out.vRefNum, out.parID, out.name, fsRdWrPerm);
- err = ResError();
- if (err) {
- CloseResFile(outRes);
- UseResFile(oldRes);
- return(err);
- }
- }
-
- HGetFInfo(out.vRefNum, out.parID, out.name, &fff);
- fff.fdCreator = gSignature;
- fff.fdType = 'PtMd';
- HSetFInfo(out.vRefNum, out.parID, out.name, &fff);
-
- for (; *oldDepth > newDepth; --*oldDepth) {
- hndl = NewHandle(3);
- pcpy((StringPtr)*hndl, "\p::");
- AddResource(hndl, 'STR ', gRsrcNum++, nil);
- ChangedResource(hndl);
- WriteResource(hndl);
- DetachResource(hndl);
- DisposeHandle(hndl);
- }
-
- if (isFolder) {
- pcpy(pstr, in.name);
- pcpy(in.name, "\p:");
- pcat(in.name, pstr);
- ++newDepth;
- }
- *oldDepth = newDepth;
-
- hndl = NewHandle(in.name[0] + 1);
- pcpy((StringPtr)*hndl, in.name);
- AddResource(hndl, 'STR ', gRsrcNum, nil);
- ChangedResource(hndl);
- WriteResource(hndl);
- DetachResource(hndl);
- DisposeHandle(hndl);
-
- if (!isFolder) {
- hndl = NewHandle(sizeof(FInfo));
- BlockMove(&finfo, *hndl, sizeof(FInfo));
- AddResource(hndl, 'fINO', gRsrcNum, nil);
- ChangedResource(hndl);
- WriteResource(hndl);
- DetachResource(hndl);
- DisposeHandle(hndl);
- }
- else {
- hndl = NewHandle(sizeof(DInfo));
- BlockMove(&dinfo, *hndl, sizeof(DInfo));
- AddResource(hndl, 'dINO', gRsrcNum, nil);
- ChangedResource(hndl);
- WriteResource(hndl);
- DetachResource(hndl);
- DisposeHandle(hndl);
- }
-
- pb.hFileInfo.ioNamePtr = in.name;
- pb.hFileInfo.ioVRefNum = in.vRefNum;
- pb.hFileInfo.ioDirID = in.parID;
- pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
- if (!PBGetCatInfoSync(&pb)) {
- date[0] = pb.hFileInfo.ioFlCrDat;
- date[1] = pb.hFileInfo.ioFlMdDat;
- hndl = NewHandle(2 * sizeof(long));
- BlockMove(&date[0], *hndl, 2 * sizeof(long));
- AddResource(hndl, 'date', gRsrcNum, nil);
- ChangedResource(hndl);
- WriteResource(hndl);
- DetachResource(hndl);
- DisposeHandle(hndl);
- }
-
- gRsrcNum++;
-
- if (isFolder) {
- CloseResFile(outRes);
- UseResFile(oldRes);
- return(noErr);
- }
-
- err = HOpenDF(in.vRefNum, in.parID, in.name, fsRdPerm, &inRef);
- if (err) {
- CloseResFile(outRes);
- UseResFile(oldRes);
- return(err);
- }
-
- err = GetEOF(inRef, &eof);
- if (err) {
- FSClose(inRef);
- CloseResFile(outRes);
- UseResFile(oldRes);
- return(err);
- }
-
- SetFPos(inRef, fsFromStart, 0);
- hndl = NewHandle(eof);
- HLock(hndl);
- err = FSRead(inRef, &eof, *hndl);
- HUnlock(hndl);
- FSClose(inRef);
- AddResource(hndl, 'dFRK', gRsrcNum - 1, nil);
- ChangedResource(hndl);
- WriteResource(hndl);
- DetachResource(hndl);
- DisposeHandle(hndl);
-
- err = HOpenRF(in.vRefNum, in.parID, in.name, fsRdPerm, &inRes);
- if (err) {
- CloseResFile(outRes);
- UseResFile(oldRes);
- return(err);
- }
-
- err = GetEOF(inRes, &eof);
- if (err) {
- FSClose(inRes);
- CloseResFile(outRes);
- UseResFile(oldRes);
- return(err);
- }
-
- SetFPos(inRes, fsFromStart, 0);
- hndl = NewHandle(eof);
- HLock(hndl);
- err = FSRead(inRes, &eof, *hndl);
- HUnlock(hndl);
- FSClose(inRes);
- AddResource(hndl, 'rFRK', gRsrcNum - 1, nil);
- ChangedResource(hndl);
- WriteResource(hndl);
- DetachResource(hndl);
- DisposeHandle(hndl);
-
- HGetFInfo(in.vRefNum, in.parID, in.name, &finfo);
-
- hndl = NewHandle(sizeof(OSType));
- BlockMove(&finfo.fdCreator, *hndl, sizeof(OSType));
- AddResource(hndl, 'cTYP', gRsrcNum - 1, nil);
- ChangedResource(hndl);
- WriteResource(hndl);
- DetachResource(hndl);
- DisposeHandle(hndl);
-
- hndl = NewHandle(sizeof(OSType));
- BlockMove(&finfo.fdType, *hndl, sizeof(OSType));
- AddResource(hndl, 'tTYP', gRsrcNum - 1, nil);
- ChangedResource(hndl);
- WriteResource(hndl);
- DetachResource(hndl);
- DisposeHandle(hndl);
-
- CloseResFile(outRes);
- UseResFile(oldRes);
-
- return(err);
- }
-
-
-
- static void IndCNum2Ctl(WindowPtr window, short ctlNum, short cset, ControlHandle *ctl)
- {
- short cid;
-
- *ctl = nil;
- if (!ctlNum) return;
-
- cid = ctlNum; /* Caller may have actually passed us a cid. */
-
- *ctl = ((WindowPeek)window)->controlList;
- for (;;) {
- if (!*ctl) break;
- if (GetControlID(*ctl) == cid) {
- --cset;
- if (cset < 1) return;
- }
- *ctl = (**ctl)->nextControl;
- }
-
- return;
- }
-
- static void VisCNum2Ctl(WindowPtr window, short ctlNum, ControlHandle *ctl)
- {
- short cid;
-
- *ctl = nil;
- if (!ctlNum) return;
-
- cid = ctlNum; /* Caller may have actually passed us a cid. */
-
- *ctl = ((WindowPeek)window)->controlList;
- for (;;) {
- if (!*ctl) break;
- if (GetControlID(*ctl) == cid) {
- if ((**ctl)->contrlVis) {
- return;
- }
- }
- *ctl = (**ctl)->nextControl;
- }
-
- CNum2Ctl(window, ctlNum, ctl);
-
- return;
- }
-
-